package teamdamn.controller;

import teamdamn.model.RFPList;

/**
 * 
 * @author jrsto674
 * @author l2m (added some methods)
 */
public class DBIO {
	
	/** The instance of DBIO */
    private static final DBIO instance = new DBIO();

	/** The location of the local data */
	private String myLocalRepository;
	
	
	/**
	 * Private DBIO (Singleton)
	 */
	private DBIO() {
		// The default path is repository.
		myLocalRepository = "repository";
	}

    /**
     * Returns the instance of DBIO
     * @return the DBIO
     */
    public static final DBIO getInstance() {
        return instance;
    }

    /**
     * Determines what OS the user is using: Windows or something else.
     * Mac and Linux File path notations use / (like Unix)
     * Only Windows OS uses \
     * @author l2m
     * @return true if Windows, else false
     */
    public static boolean isWindows(){

    	String OS = System.getProperty("os.name").toLowerCase();
    	return (OS.indexOf("win") >= 0);
    }

    /**
     * Returns the path separator character appropriate to the user OS
     * @author l2m
     * @return the path separator character appropriate to the user OS
     */
    public static char PathSeparator(){
    	if (isWindows()){
    		return '\\';
    	}
    	return '/';
    }
    
    /**
     * Checks status of network connection.
     * @return boolean on connection status.
     */
	public boolean isNetworkConnected() {
		return true;
	}
	
	/**
	 * The path to the local file repository.
	 * My be changed in future.
	 * Accessed by DBIO, RPF and response list
	 * 
	 * @author l2m
	 * @return the path to the local file repository
	 */
	public String getRepositoryLocation() {
		return myLocalRepository;
	}
	
	/**
	 * Checks network connection status and retrieves updated data if such
	 * data exists upon finding a conneciton.
	 */
	public void refreshData() {
		// Notify Observers of start //
		
		// Confirm network connection //
		if (isNetworkConnected()) {
			// Check revision number on local data //
			// vs revision number on network data //
			
			// If network version newer, download //
			
			
		}
		
		// Notify observers of completion //
	}
	
	public String getData(String type) {
		switch (type) {
			case "userLog":
				
				break;
			case "RFPList":
				
				break;
			case "RFPLocation":
				
				break;
		}
		return "";
	}
	
	public void setData(String data, String type) {
		switch (type) {
		case "userLog":
			
			break;
		case "RFPList":
			
			break;
		case "RFPLocation":
			
			break;
		}
	}
	
	// Are these two needed with the dummy implementation we settled on?
	public String getNetwork() {
		return "";
	}
	
	public void setNetwork() {
		
	}
}
